package framework
import (
	"signaling/src/goconfig"
)
type FrameworkConf struct {
//log
	logDir string
	logFile string
	logLevel string
	logToStderr bool
//http
	httpPort int
	httpStaticDir string
	httpStaticPrefix string 
//https
	httpsPort int
	httpsCert string
	httpsKey string

}
var configFile *goconfig.ConfigFile
func loadConf(confFile string) (*FrameworkConf,error) {
	var err error
	configFile,err = goconfig.LoadConfigFile(confFile)
	if err != nil {
		return nil, err
	}
	conf := &FrameworkConf{}

	//log
	conf.logDir,err = configFile.GetValue("log","logDir")
	if err != nil {
		return nil, err
	}
	conf.logFile,err = configFile.GetValue("log","logFile")
	if err != nil {
		return nil,err
	}
	conf.logLevel,err = configFile.GetValue("log","logLevel")
	if err != nil {
		return nil,err
	}
	conf.logToStderr,err = configFile.Bool("log","logToStderr")
	if err != nil {
		return nil,err
	}


	//http

	conf.httpPort,err = configFile.Int("http","port")
	if err != nil {
		return nil,err
	}

	conf.httpStaticDir,err = configFile.GetValue("http","staticDir")
	if err != nil {
		return nil,err
	}
	conf.httpStaticPrefix,err = configFile.GetValue("http","staticPrefix")
	if err != nil {
		return nil,err
	}

	//https
	conf.httpsPort,err = configFile.Int("https","port")
	if err != nil {
		return nil,err
	}

	conf.httpsCert,err = configFile.GetValue("https","cert")
	if err != nil {
		return nil,err
	}

	conf.httpsKey,err = configFile.GetValue("https","key")
	if err != nil {
		return nil,err
	}

	return conf,nil
}

//action 和framework 不在一个包不能直接访问，需要暴露一个方法
func GetStaticDir() string {

	return gconf.httpStaticDir
}